package org.itcast.travel.controller;

import lombok.extern.slf4j.Slf4j;
import org.itcast.travel.exception.UpdPwdExcepton;
import org.itcast.travel.pojo.*;
import org.itcast.travel.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;
    //登录
    @PostMapping("/login")
    public Result login(@RequestBody User user) throws Exception {
        log.info("登录,参数:{}", user);
        LoginInfo loginInfo =userService.login(user);
        return Result.success(loginInfo);
    }
    //注册
    @PostMapping("/register")
    public Result register(@RequestBody UserInfoS userInfoS) {
        log.info("SDSADa{}",userInfoS);
        userService.register(userInfoS);
        return Result.success();
    }
    //根据id查询用户信息（回显）
    @GetMapping("/{id}")
    public Result getById(Integer id){
        UserInfo userInfo = userService.getById(id);
        return Result.success(userInfo);
    }
    //修改用户信息
    @PutMapping
    public Result updateUser(@RequestBody UserInfo userInfo){
        userService.updateUser(userInfo);
        return Result.success();
    }
    //账号注销
    @GetMapping("/del")
    public Result delUser(Integer id){
        userService.delUser(id);
        return Result.success();
    }
    //修改密码
    @GetMapping ("/updatePassword")
    public Result updatePassword(User user) throws UpdPwdExcepton {
        userService.updateUserPasswrod(user);
        return Result.success();
    }

}
